<!doctype html>
<html>
  <head>
    <title>Test GC of AudioBufferSourceNode</title>
    <script>
      var context;
      var bufferLengthSeconds = 120;
      var count = 0;

      function runTest() {

        // Create the context
        context = new AudioContext();

        // Continuously create AudioBufferSourceNodes with large AudioBuffers and immediately drop
        // the references.  This should not crash the browser.
        setInterval(function () {
                     var source = context.createBufferSource();
                     var buffer = context.createBuffer(1, bufferLengthSeconds * context.sampleRate, context.sampleRate);
                     source.buffer = buffer;
                     buffer = null;
                     source = null;
                     ++count;
                     if ((count % 100) == 0)
                       console.log(count + " nodes generated");
                   }, 10);
      }
    </script>
  </head>

  <body>
    <p>
      This tests that we clear up source buffers that were never connected nor started. Press the
      button to run the test.  If everything is working correctly, there will be no crash. Watch the
      messages in the console. Run this for at least 5000 nodes (see console for node count).
    </p>
    <button onclick="runTest()">Run AudioBufferSourceNode GC Test</button>
  </body>
</html>
